package com.cs4590.finalProject.userInterface;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cs4590.finalProject.ObjectDatabase;
import com.cs4590.finalProject.R;
import com.cs4590.finalProject.YouPiano;

public class SoundsDialog extends Activity {

	ObjectDatabase od;

	public void onCreate(Bundle b) {
		super.onCreate(b);
		setContentView(R.layout.dialog_sounds);
		
		YouPiano app = (YouPiano) this.getApplication();
		od = app.getOd();
		
		showFiles();
	}


	private void showFiles() {
		try {
			LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout_dialog);
			layout.removeAllViews();

			ArrayList<String> names = od.getAll();

			for(String name : names) {
				TextView temp = new TextView(this);
				temp.setTextColor(Color.BLACK);
				temp.setTextSize(18);
				temp.setClickable(true);
				temp.setOnClickListener(new TextListener());
				temp.setText(name);
				layout.addView(temp);
			}
			TextView temp = new TextView(this);
			temp.setTextColor(Color.BLACK);
			temp.setTextSize(18);
			temp.setClickable(true);
			temp.setOnClickListener(new TextListener());
			temp.setText("default");
			layout.addView(temp);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private class TextListener implements View.OnClickListener {
		public void onClick(View v) {
			TextView text = (TextView) v;
			
			Intent resultIntent = new Intent(SoundsDialog.this, SoundsDialog.class);
			resultIntent.putExtra("name", text.getText().toString());
			setResult(Activity.RESULT_OK, resultIntent);
			finish();
		}
	}
}
